﻿Public Class Hospedar
    Dim rs As ADODB.Recordset
    Dim sql As String
    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        Try
            sql = "SELECT CODI_HABI, NUME_HABI FROM(HABITACION) WHERE (NUME_HABI = '" & ListaHabitacion.SelectedItem.ToString & "')"
            rs = coneccion.Execute(sql)
            sql = "INSERT INTO REGISTRO_HABITACION(CODI_CLIEN, CODI_HABI, NUME_DIAS, FECHA_HABITA,CANCELADO) VALUES ('" & txtCodigo.Text & "','" & rs.Fields(0).Value.ToString & "','" & numericDias.Value.ToString & "','" & FechaActual.Value.ToString & "','NO')"
            rs = coneccion.Execute(sql)
            Me.Dispose()
        Catch ex As Exception
            MsgBox("Usuario Hospedado elija otro", MsgBoxStyle.Exclamation, "Error")
        End Try
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Dispose()
    End Sub
    Public Sub llenar(ByVal Resultado As String)
        sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN  FROM CLIENTE WHERE (CODI_CLIEN = '" & Resultado & "')"
        rs = coneccion.Execute(sql)
        txtNombre.Text = rs.Fields(1).Value
        txtAPaterno.Text = rs.Fields(2).Value
        txtAMaterno.Text = rs.Fields(3).Value
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTipo.SelectedIndexChanged
        ListaHabitacion.Items.Clear()

        sql = "SELECT HABITACION.NUME_HABI, HABITACION.ENUSO_HABI, TIPO_HABITACION.TIPO_HABITACION FROM (TIPO_HABITACION INNER JOIN HABITACION ON TIPO_HABITACION.CODIGO_TIPO = HABITACION.CODIGO_TIPO) WHERE (TIPO_HABITACION.TIPO_HABITACION = '" & CmbTipo.SelectedItem.ToString & "') AND (HABITACION.ENUSO_HABI = 'NO')"
        rs = coneccion.Execute(sql)
        While rs.EOF <> True
            If rs.EOF = True Then
                Exit While
            End If
            ListaHabitacion.Items.Add(rs.Fields(0).Value)
            rs.MoveNext()
        End While
        sql = "SELECT COSTO_HABITACION, TIPO_HABITACION FROM(TIPO_HABITACION) WHERE(TIPO_HABITACION = '" & cmbTipo.SelectedItem.ToString & "')"
        rs = coneccion.Execute(sql)
        txtCostoDia.Text = rs.Fields(0).Value.ToString
        'Filtrar lisbox las habitaciones por su tipo
    End Sub

    Private Sub btnVerificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerificar.Click
        Dim mostrar As New Resultados(txtAPaterno.Text, txtAMaterno.Text, txtNombre.Text, txtCodigo.Text)
        mostrar.Show()
    End Sub

    Private Sub Hospedar_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
        llenar(Resultado)
        txtCodigo.Text = Resultado
    End Sub

    Private Sub Hospedar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conectar()
        sql = "SELECT TIPO_HABITACION FROM TIPO_HABITACION"
        rs = coneccion.Execute(sql)
        While rs.EOF <> True
            If rs.EOF = True Then
                Exit While
            End If
            cmbTipo.Items.Add(rs.Fields(0).Value)
            rs.MoveNext()
        End While
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        txtCodigo.Text = ""
        txtAPaterno.Text = ""
        txtAMaterno.Text = ""
        txtNombre.Text = ""
        txtCostoDia.Text = ""
    End Sub
End Class